package com.lcz.fruitweb.web;


import com.lcz.fruitweb.service.FruitService;
import com.lcz.fruitweb.service.impl.FruitServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/fruitDel")
public class FruitDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String strId = req.getParameter("id");
        int id = Integer.parseInt(strId);
        ApplicationContext applicationContext =(ApplicationContext) getServletContext().getAttribute("applicationContext");
        FruitService fruitService = applicationContext.getBean("fruitService",FruitService.class);
        fruitService.delFruitById(id);

        resp.sendRedirect("fruitList");


    }
}
